﻿using UnityEngine;
using System.Collections;

public class OnScreenMessageManager : MonoBehaviour {

    public GameObject onScreenXP;
    public GameObject onScreenLevelUp;
    public GameObject OnScreenEnemyDamage;

	// Use this for initialization
	void Start () {

        EventManager<int, Vector3>.AddListener("xp gain", onXPGain);
        EventManager<int>.AddListener("level up", onLevelUp);
        EventManager<GameObject, int>.AddListener("enemy recieve dmg", onEnemyRecieveDamage);
	}
	
	// Update is called once per frame
	void Update () {
	
	}


    private void onXPGain(int gain, Vector3 position)
    {
        GameObject obj = (GameObject)Instantiate(onScreenXP, position, Quaternion.identity);
        obj.GetComponent<OnScreenXP>().Xp = gain;
    }

    private void onLevelUp(int level)
    {
        GameObject obj = (GameObject)Instantiate(onScreenLevelUp, Camera.main.WorldToScreenPoint(transform.position), Quaternion.identity);
        obj.GetComponent<OnScreenLevelUp>().Level = level;
    }

    private void onEnemyRecieveDamage(GameObject enemy, int dmg)
    {
        GameObject obj = (GameObject)Instantiate(OnScreenEnemyDamage, enemy.transform.position, Quaternion.identity);
        obj.GetComponent<OnScreenEnemyDamage>().Dmg = dmg;
    }
}
